// web/src/app/learn/(course)/courses/[courseId]/page.tsx
import React from 'react';
import {db} from "@/lib/db";
import {redirect} from "next/navigation";

const Page =async ({
                  params
              }: {
    params: { courseId: string }
}) => {
    const course = await db.course.findUnique({
        where: {
            id: params.courseId
        },
        include: {
            chapters: {
                where: {
                    isPublished: true
                },
                orderBy: {
                    position: 'asc'
                }
            }
        }
    })

    if (!course) return redirect(`/learn`)

    return redirect(`/learn/courses/${course.id}/chapters/${course.chapters[0].id}`)
};

export default Page;